package com.tjshop.android.adapter;

import java.util.List;

import com.tjshop.android.R;
import com.tjshop.android.model.tj.json.Goods;
import com.tjshop.android.util.ImageLoaderUtils;

import android.content.Context;  
import android.graphics.Bitmap;  
import android.graphics.drawable.Drawable;  
import android.media.ThumbnailUtils;  
import android.view.LayoutInflater;  
import android.view.View;  
import android.view.ViewGroup;  
import android.widget.BaseAdapter;  
import android.widget.ImageView;  
import android.widget.TextView;  
  
public class HorizontalListViewAdapter extends BaseAdapter{  
    private List<Goods> gl;  
    private Context mContext;  
  
    public HorizontalListViewAdapter(Context context, List<Goods> gl){  
        this.mContext = context;  
        this.gl = gl;  
    }  
    @Override  
    public int getCount() {  
        return gl.size();  
    }  
    @Override  
    public Object getItem(int position) {  
        return position;  
    }  
  
    @Override  
    public long getItemId(int position) {  
        return position;  
    }  
  
    @Override  
    public View getView(int position, View convertView, ViewGroup parent) {  
  
        ViewHolder holder;  
        if(convertView==null){  
            holder = new ViewHolder();  
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_relative_item, null);  
            holder.mImage=(ImageView)convertView.findViewById(R.id.icon);  
            holder.mTitle=(TextView)convertView.findViewById(R.id.name);  
            holder.mPrice = (TextView) convertView.findViewById(R.id.price);
            convertView.setTag(holder);  
        }else{  
            holder=(ViewHolder)convertView.getTag();  
        }  
          
        holder.mTitle.setText(gl.get(position).getGoods_name());
        holder.mPrice.setText("￥"+gl.get(position).getShop_price());
        ImageLoaderUtils.getInstance(mContext).displayImage(gl.get(position).getGoods_thumb(), holder.mImage); 
//  
        return convertView;  
    }  
  
    private static class ViewHolder {  
        private TextView mTitle ; 
        private TextView mPrice;
        private ImageView mImage;  
    }  
}